﻿(function(E, T, $){
var selection = E.mod('Selection'),
	testName = 'InsertTable',
	title = '表格操作',
	setValue = '<table border="1" bordercolor="#cccccc" cellpadding="5" width="90%">\
	<tbody>\
		<tr>\
			<th>删除标题行</th>\
			<th>&nbsp;</th>\
			<th>&nbsp;</th>\
		</tr>\
		<tr>\
			<td><span id="_testTable_1">&nbsp;</span></td>\
			<td><span id="_testTable_2">&nbsp;</span></td>\
			<td><span id="_testTable_3">&nbsp;</span></td>\
		</tr>\
		<tr>\
			<td><span id="_testTable_4">&nbsp;</span></td>\
			<td><span id="_testTable_5">&nbsp;</span></td>\
			<td><span id="_testTable_6">&nbsp;</span></td>\
		</tr>\
	</tbody>\
</table>&nbsp;<div id="_testTable">&nbsp;</div>',
	dom = null,
	node = null,
	cmds = [
		[1500, {fun: function() {
			dom = E.get('document');
			dom.body.innerHTML = setValue;
			node = dom.getElementById('_testTable');
			selection.selectNode(node, true);
			//模拟移动光标，没有记录当前光标所在节点，
			//导致部分菜单不可用，所以这里可以调用一下节点的mousedown方法
			//记录当前光标所在节点
			$(node).trigger('mousedown');
		}}],
		[500, {name: '#demo-InsertTable', type: 'mouseover'}],
		[500, {name: '#demo-InsertTable span.InsertTable', type: 'click'}],
		[500, {name: '#panel_InsertTable td[ij=2-2]', type: 'mouseover'}],
		[500, {name: '#panel_InsertTable td[ij=3-3]', type: 'mouseover'}],
		[500, {name: '#panel_InsertTable td[ij=3-3]', type: 'click'}],
		[500, {fun: function() {
			selection.selectNode(node, false);
			//模拟移动光标，没有记录当前光标所在节点，
			//导致部分菜单不可用，所以这里可以调用一下节点的mousedown方法
			//记录当前光标所在节点
			$(node).trigger('mousedown');
		}}],
		[500, {name: '#demo-InsertTable', type: 'mouseover'}],
		[1000, {name: '#demo-InsertTable a.jqe-button-menu', type: 'click'}],
		[200, {name: '#jqe-InsertTable-0 li[menuname=InsertTable]', type: 'mouseover'}],
		[200, {name: '.jqe-menu #jqe-plugin-table td[ij=1-1]', type: 'mouseover'}],
		[200, {name: '.jqe-menu #jqe-plugin-table td[ij=2-2]', type: 'mouseover'}],
		[200, {name: '.jqe-menu #jqe-plugin-table td[ij=3-3]', type: 'mouseover'}],
		[200, {name: '.jqe-menu #jqe-plugin-table td[ij=4-4]', type: 'mouseover'}],
		[500, {name: '.jqe-menu #jqe-plugin-table td[ij=4-4]', type: 'click'}],//下面开始测试表格菜单
		[100, {fun: function(){
			node = dom.getElementById('_testTable_1');
			selection.selectNode(node, false);
			$(node).trigger('mousedown');
		}}],
		[500, {name: '#demo-InsertTable', type: 'mouseover'}],
		[1000, {name: '#demo-InsertTable a.jqe-button-menu', type: 'click'}],
		[300, {name: '#jqe-InsertTable-0 li[menuname=RemoveTableTitleRow]', type: 'mouseover'}],
		[500, {name: '#jqe-InsertTable-0 li[menuname=RemoveTableTitleRow] a', type: 'click'}],
		[100, {fun: function() {
			node.innerHTML = '删除表格标题行';
			node = dom.getElementById('_testTable_2');
			selection.selectNode(node, false);
			$(node).trigger('mousedown');
		}}],
		[500, {name: '#demo-InsertTable', type: 'mouseover'}],
		[1000, {name: '#demo-InsertTable a.jqe-button-menu', type: 'click'}],
		[300, {name: '#jqe-InsertTable-0 li[menuname=addTableTitleRow]', type: 'mouseover'}],
		[500, {name: '#jqe-InsertTable-0 li[menuname=addTableTitleRow] a', type: 'click'}],
		[100, {fun: function() {
			node.innerHTML = '添加表格标题行';
			node = dom.getElementById('_testTable_3');
			selection.selectNode(node, false);
		}}],
		[500, {name: '#demo-InsertTable', type: 'mouseover'}],
		[1000, {name: '#demo-InsertTable a.jqe-button-menu', type: 'click'}],
		[300, {name: '#jqe-InsertTable-0 li[menuname=addTableCaption]', type: 'mouseover'}],
		[500, {name: '#jqe-InsertTable-0 li[menuname=addTableCaption] a', type: 'click'}],
		[100, {fun: function() {
			node.innerHTML = '添加表格名称';
			node = dom.getElementById('_testTable_4');
			selection.selectNode(node, false);
			$(node).trigger('mousedown');
		}}],
		[500, {name: '#demo-InsertTable', type: 'mouseover'}],
		[1000, {name: '#demo-InsertTable a.jqe-button-menu', type: 'click'}],
		[300, {name: '#jqe-InsertTable-0 li[menuname=Insert]', type: 'mouseover'}],
		[300, {name: '#jqe-InsertTable-0 a[name=RowInsertAfter]', type: 'mouseover'}],
		[300, {name: '#jqe-InsertTable-0 a[name=RowInsertAfter]', type: 'click'}],
		[100, {fun: function() {
			node.innerHTML = '下方插入行';
		}}]
	];

T.addTest(testName, cmds, title);
})(jQEditor,AutoTest, jQuery)